.SUFFIXES: .c .o .lo

COMPILE = $(CC) $(CFLAGS)
INC_PATH = -I../common
LIB_PATH = $(LIBS) -lfastcommon -lserverframe -lfcfsauthclient
TARGET_LIB = $(TARGET_PREFIX)/$(LIB_VERSION)

FAST_SHARED_OBJS = ../common/fdir_global.lo ../common/fdir_proto.lo \
                   ../common/fdir_func.lo client_func.lo \
                   client_global.lo client_proto.lo fdir_client.lo  \
                   simple_connection_manager.lo pooled_connection_manager.lo

FAST_STATIC_OBJS = ../common/fdir_global.o ../common/fdir_proto.o \
                   ../common/fdir_func.o client_func.o \
                   client_global.o client_proto.o fdir_client.o  \
                   simple_connection_manager.o pooled_connection_manager.o

HEADER_FILES = ../common/fdir_types.h ../common/fdir_server_types.h \
               ../common/fdir_global.h ../common/fdir_proto.h \
               ../common/fdir_func.h fdir_client.h client_types.h \
               client_func.h client_global.h client_proto.h \
               simple_connection_manager.h pooled_connection_manager.h

ALL_OBJS = $(FAST_STATIC_OBJS) $(FAST_SHARED_OBJS)

ALL_PRGS = 
SHARED_LIBS = libfdirclient.so
STATIC_LIBS = libfdirclient.a
ALL_LIBS = $(SHARED_LIBS) $(STATIC_LIBS)

all: $(ALL_OBJS) $(ALL_PRGS) $(ALL_LIBS)
libfdirclient.so: $(FAST_SHARED_OBJS)
	$(COMPILE) -o $@ -shared $(FAST_SHARED_OBJS) $(LIB_PATH)
libfdirclient.a: $(FAST_STATIC_OBJS)
	ar rcs $@ $(FAST_STATIC_OBJS)
.o:
	$(COMPILE) -o $@ $<  $(FAST_STATIC_OBJS) $(LIB_PATH) $(INC_PATH)
.c:
	$(COMPILE) -o $@ $<  $(FAST_STATIC_OBJS) $(LIB_PATH) $(INC_PATH)
.c.o:
	$(COMPILE) -c -o $@ $<  $(INC_PATH)
.c.lo:
	$(COMPILE) -c -fPIC -o $@ $<  $(INC_PATH)
install:
	mkdir -p $(TARGET_LIB)
	mkdir -p $(TARGET_PREFIX)/lib
	mkdir -p $(TARGET_PREFIX)/include/fastdir/client

	install -m 755 $(SHARED_LIBS) $(TARGET_LIB)
	install -m 644 $(HEADER_FILES) $(TARGET_PREFIX)/include/fastdir/client
	@BUILDROOT=$$(echo "$(TARGET_PREFIX)" | grep BUILDROOT); \
	if [ -z "$$BUILDROOT" ] && [ "$(TARGET_LIB)" != "$(TARGET_PREFIX)/lib" ]; then ln -sf $(TARGET_LIB)/libfdirclient.so $(TARGET_PREFIX)/lib/libfdirclient.so; fi
clean:
	rm -f $(ALL_OBJS) $(ALL_PRGS) $(ALL_LIBS)

